package com.slg.android.manyanime.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.slg.android.manyanime.R;
import com.slg.android.manyanime.bean.Animation;
import com.slg.android.manyanime.utils.DataStore;

import java.util.List;

/**
 * Created by E540 on 2015/3/11.
 */
public class AnimeRecommendAdapter extends BaseAdapter {
    private Context context;
    private List<Animation> data;

    public AnimeRecommendAdapter(Context context, List<Animation> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }



    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.
                    from(context).inflate(R.layout.item_anime_recommend, parent, false);
        }
        ViewHolder holder = (ViewHolder) convertView.getTag();
        if (holder == null) {
            holder = new ViewHolder();
            convertView.setTag(holder);
        }
        ViewUtils.inject(holder, convertView);
        Animation item = (Animation) getItem(position);
        holder.name.setText(item.getName());
        holder.lastUp.setText(item.getLastUp());

        BitmapUtils bitmapUtils = DataStore.getBitmapUtils();
        bitmapUtils.configDefaultLoadingImage(R.drawable.item_default);
        bitmapUtils.display(holder.pic,item.getPic());

        return convertView;
    }

    public class ViewHolder {
        @ViewInject(R.id.item_anime_recommend_pic_ImageView)
        public ImageView pic;
        @ViewInject(R.id.item_anime_recommend_name_TextView)
        public TextView name;
        @ViewInject(R.id.item_anime_recommend_lastup_TextView)
        public TextView lastUp;

    }
}
